using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using QLTV.Database;
using System.Collections.Generic;
using System.Linq;

namespace QLTV.Reports
{
    public partial class rpNotInVinic : DevExpress.XtraReports.UI.XtraReport
    {
        public rpNotInVinic()
        {
            InitializeComponent();
            bindingData();
        }

        public int STT
        {
            get
            {
                return CurrentRowIndex + 1;
            }
        }
        private string getDiaChi(string s, bool end)
        {
            if (String.IsNullOrEmpty(s))
                return "";
            else
            {
                if (!end)
                    return s + ",";
                else
                    return s;
            }
        }

        ReportDataContext data = new ReportDataContext();
        public void bindingData()

        {

            lblEmployeeName.Text = Program.EmployeeName;
            var query = from c in data.tblAssignment_rps
                        orderby c.tblCrew_rp.tblRank_rp.nRankLevel ascending
                        where c.isActive == true && (c.cStatus == "On Resign" || c.cStatus == "On Retire")
                        select new
                        {
                            MaSo = c.nCrewid,
                            ChucDanh = c.tblCrew_rp.tblRank_rp.cRankName,
                            Ho = c.tblCrew_rp.cFamilyName,
                            TenDem = c.tblCrew_rp.cMiddleName,
                            Ten = c.tblCrew_rp.cFirstName,
                            DienThoaiCoDinh = c.tblCrew_rp.cHomeNo,
                            DTDT = c.tblCrew_rp.cHandNo,
                            DiaChi = String.Format("{0} {1} {2} {3}", getDiaChi(c.tblCrew_rp.cAddress, false), getDiaChi(c.tblCrew_rp.tblPhuongXa_rp.TenPhuongXa, false), getDiaChi(c.tblCrew_rp.tblQuanHuyen_rp.TenQuanHuyen, false), getDiaChi(c.tblCrew_rp.tblTinhThanh_rp.TenTinhThanh, true)),
                            TrangThai = c.cStatus,
                            
                        };
            
            this.DataSource = query;

            this.colSTT.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", this, "STT")});
            this.colMaSo.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "MaSo")});
            this.colChucDanh.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "ChucDanh")});
            this.colHo.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "Ho")});
            this.colTenDem.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "TenDem")});
            this.colTen.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "Ten")});
            this.colDienThoaiCoDinh.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "DienThoaiCoDinh")});
            this.colDTDD.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "DTDT")});
            this.colDiaChi.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "DiaChi")});
            this.colTrangThaiHienTai.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "TrangThai")});
        }

     
        private void colSTT_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {

        }
        
    }
}
